RAIS  3.2
C:/Projekte/RAIS/Specific Masks/EditTranslation.aspx.cs
Go to the documentation of this file.
00001 
00028 using System;
00029 using System.Data;
00030 using System.Configuration;
00031 using System.Collections;
00032 using System.Web;
00033 using System.Web.Security;
00034 using System.Web.UI;
00035 using System.Web.UI.WebControls;
00036 using System.Web.UI.WebControls.WebParts;
00037 using System.Web.UI.HtmlControls;
00038 using System.Collections.Generic;
00039 
00040 using RAIS.Common.UserManagement;
00041 using RAIS.ApplicationLogicLayer;
00042 
00043 using Cultures = System.Collections.Generic.Dictionary<string, RAIS.Common.Localization.Culture>;
00044 using Contexts = System.Collections.Generic.Dictionary<string, RAIS.Common.Localization.Context>;
00045 using TranslationItems = System.Collections.Generic.Dictionary<string, RAIS.Common.Localization.TranslationItem>;
00046 
00047 namespace RAIS.UI.SpecificMasks
00048 {
00052     public partial class EditTranslation : System.Web.UI.Page
00053     {
00054                 #region Properties
00055         private Dictionary<string, string> contextNames = new Dictionary<string, string>();
00056                 #endregion
00057         #region Event handlers
00058         protected void Page_PreLoad(object sender, EventArgs e)
00059         {
00060             RAIS.UI.Common.PageManagement.TrimTextBoxValues(this);
00061         }
00068         protected void Page_Load(object sender, EventArgs e)
00069         {
00070                         this.Response.Cache.SetNoStore();
00071                         if (this.CurrentUser == null)
00072                                 UI.Common.AccessManagement.SignOut(this);
00073                         
00074                         if (!this.IsPostBack)
00075             {
00076                 FillPageNames();
00077                 this.LBLusernameNoTranslation.Text = this.CurrentUser.Name;
00078                                 this.SortExpression = RAIS.Common.Constants.SORT_EXPRESSION;
00079                                 this.SortDirection = RAIS.Common.Constants.SORT_ORDER_ASCENDING;
00080                                 
00081                                 UI.Common.Localisation.InitializeLanguagesSelection(this.DDLsource.Items);
00082                 UI.Common.Localisation.InitializeLanguagesSelection(this.DDLdestination.Items);
00083                 UI.Common.Localisation.InitializeContextsList(this.DDLcontext.Items);
00084 
00085                 Cultures supportedLanguages = RAIS.ApplicationLogicLayer.Localisation.SupportedLanguages;
00086                 this.SelectedSourceCulture = supportedLanguages[RAIS.Common.Constants.DEFAULT_LANGUAGE];
00087 
00088                 RAIS.Common.Localization.Culture targetCulture = (RAIS.Common.Localization.Culture)this.Session[RAIS.UI.Common.Constants.SELECTED_TARGET_CULTURE];
00089                 if (targetCulture != null)
00090                     this.SelectedTargetCulture = targetCulture;
00091 
00092                 ListItem sourceLanguageInDestinationList = this.DDLdestination.Items.FindByText(this.DDLsource.SelectedItem.Text);
00093                 if (sourceLanguageInDestinationList != null)
00094                 {
00095                     this.DDLdestination.Items.Remove(sourceLanguageInDestinationList);
00096                 }
00097 
00098                 this.InitializeTranslations();
00099 
00100                 UI.Common.PageManagement.InitializePage(this, this.TreeView1);
00101 //                              this.LBTNmessagebox.Visible = !(this.CurrentUser.FunctionalRole.Type == FunctionRole.FunctionRoleType.Guest);
00102 
00103                 this.EditMode = false;
00104             }
00105 
00106             this.LBLresult.Text = string.Empty;
00107             if (Request.Form["__EVENTTARGET"] == UI.Common.Constants.TREEVIEW_ID)
00108                 UI.Common.UserManagement.ProcessTreeViewOnRedirect(this.TreeView1);
00109             UI.Common.PageManagement.InitHelpMainMenu(LBTNdefault);
00110         }
00111 
00112                 protected void gwCaptions_Sorting(object sender, GridViewSortEventArgs e)
00113                 {
00114                         this.SortDirection =
00115                                 (this.SortExpression == e.SortExpression)
00116                                         ? ((this.SortDirection == RAIS.Common.Constants.SORT_ORDER_DESCENDING)
00117                                                 ? RAIS.Common.Constants.SORT_ORDER_ASCENDING
00118                                                 : RAIS.Common.Constants.SORT_ORDER_DESCENDING)
00119                                         : RAIS.Common.Constants.SORT_ORDER_ASCENDING;
00120                         this.SortExpression = e.SortExpression;
00121 
00122                         this.InitializeTranslations();
00123                 }
00130         protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
00131         {
00132            //UI.Common.UserManagement.ProcessTreeViewOnRedirect(this.TreeView1);
00133         }
00134 
00142         protected void BTNedit_Click(object sender, EventArgs e)
00143         {
00144             this.EditMode = true;
00145             EnableDisableControls();
00146                 }
00154         protected void BTNdiscard_Click(object sender, EventArgs e)
00155         {
00156             this.EditMode = false;
00157         }
00166         protected void btnSubmit_Click(object sender, EventArgs e)
00167         {
00168             TranslationItems translations = this.SelectedTranslations;
00169             string actionMessage="";
00170 
00171             foreach (GridViewRow row in gwCaptions.Rows)
00172             {
00173                 TextBox txtDestLanguageCaption = (TextBox)row.FindControl(RAIS.UI.Common.Constants.TRANSLATION_EDIT_TEXT);
00174                 HiddenField hdnTranslationName = (HiddenField)row.FindControl(RAIS.UI.Common.Constants.TRANSLATION_ITEM_NAME);
00175                 translations[hdnTranslationName.Value].TargetText = txtDestLanguageCaption.Text;
00176             }
00177             bool success = RAIS.ApplicationLogicLayer.Localisation.SaveTranslations(translations, ref actionMessage);
00178             if (success)
00179                 this.EditMode = false;
00180 
00181             RAIS.UI.Common.MessageDisplay.DisplayReturnMessage(this.LBLresult, actionMessage, success);
00182         }
00189         protected void BTNautocomplete_Click(object sender, EventArgs e)
00190         {
00191             this.Autocomplete();
00192         }
00193 
00200         protected void RBLoptions_SelectedIndexChanged(object sender, EventArgs e)
00201         {
00202             this.InitializeTranslations();
00203             EnableDisableControls();
00204             this.DDLcontext.Enabled = !this.CBshowAllContexts.Checked;
00205         }
00212         protected void DDLcontext_SelectedIndexChanged(object sender, EventArgs e)
00213         {
00214             this.InitializeTranslations();
00215             EnableDisableControls();
00216             this.DDLcontext.Enabled = !this.CBshowAllContexts.Checked;
00217         }
00224         protected void DDLdestination_SelectedIndexChanged(object sender, EventArgs e)
00225         {
00226             string selectedValue = DDLdestination.SelectedValue;
00227             UI.Common.Localisation.InitializeLanguagesSelection(this.DDLdestination.Items);
00228             ListItem sourceLanguageInDestinationList = this.DDLdestination.Items.FindByText(this.DDLsource.SelectedItem.Text);
00229             if (sourceLanguageInDestinationList != null)
00230             {
00231                 this.DDLdestination.Items.Remove(sourceLanguageInDestinationList);
00232             }
00233             DDLdestination.SelectedValue = selectedValue;
00234             this.InitializeTranslations();
00235             EnableDisableControls();
00236             this.DDLcontext.Enabled = !this.CBshowAllContexts.Checked;
00237         }
00244         protected void DDLsource_SelectedIndexChanged(object sender, EventArgs e)
00245         {
00246             this.InitializeTranslations();
00247         }
00254         protected void CBshowAllContexts_CheckedChanged(object sender, EventArgs e)
00255         {
00256             this.InitializeTranslations();
00257             EnableDisableControls();
00258             this.DDLcontext.Enabled = !this.CBshowAllContexts.Checked;
00259         }
00266         protected void LBTNlogout_Click(object sender, EventArgs e)
00267         {
00268             UI.Common.AccessManagement.SignOut(this);
00269         }
00270         #endregion
00271         #region Private helper methods
00272         private void FillPageNames()
00273         {
00274             contextNames.Add("ASP.addeditusers_aspx", "Users");
00275             contextNames.Add("ASP.admin_aspx", "Admin");
00276             contextNames.Add("ASP.customtables_aspx", "Tables");
00277             contextNames.Add("ASP.default_aspx", "Home Page");
00278             contextNames.Add("ASP.dynamic_masks_listwithfilter_aspx", "List With Filter");
00279             contextNames.Add("ASP.dynamic_masks_singlerowmask_aspx", "Single Row Mask");
00280             contextNames.Add("ASP.dynamic_masks_singlerowmaskwithlist_aspx", "Single Row Mask with List");
00281             contextNames.Add("ASP.editdataroles_aspx", "Data roles (OLD)");
00282             contextNames.Add("ASP.editdataroles_new_aspx", "Data roles");
00283             contextNames.Add("ASP.editfunctionalroles_aspx", "Functional roles (OLD)");
00284             contextNames.Add("ASP.editfunctionalroles_new_aspx", "Functional roles");
00285             contextNames.Add("ASP.edittranslation_aspx", "Language selection");
00286             contextNames.Add("ASP.export_aspx", "Export");
00287             contextNames.Add("ASP.import_aspx", "Import");
00288             contextNames.Add("ASP.input_aspx", "Input");
00289             contextNames.Add("ASP.loginpage_aspx", "Login");
00290             contextNames.Add("ASP.mainexport_aspx", "Main Export");
00291             contextNames.Add("ASP.mainimport_aspx", "Main Import");
00292             contextNames.Add("ASP.messagebox_aspx", "Message Box");
00293             contextNames.Add("ASP.query_aspx", "Query");
00294             contextNames.Add("ASP.regionalsettings_aspx", "Regional Settings");
00295             contextNames.Add("ASP.regsys_aspx", "Regulatory System");
00296             contextNames.Add("ASP.statistics_aspx", "Statistics");
00297             contextNames.Add("ASP.tools_aspx", "Tools");
00298             contextNames.Add("ASP.usermanage_aspx", "Manage Users");
00299             contextNames.Add("Diagnostics messsages", "Diagnostics Messsages");
00300             contextNames.Add("TreeView1", "Side Menu");
00301             contextNames.Add("ASP.searchtool_aspx", "Search Tool");
00302             contextNames.Add("ASP.radevsearchtool_aspx", "RADEV Tool");
00303             contextNames.Add("ASP.sealedsourceactivity_aspx", "Source Activity");
00304             contextNames.Add("ASP.dynamic_masks_reportmask_aspx", "Reports");
00305 
00306             contextNames.Add("ASP.editdataroles_new_update1_aspx", "Data Role Details");
00307             contextNames.Add("ASP.editfunctionalroles_new_update1_aspx", "Functional Role Details");
00308             contextNames.Add("ASP.editfunctionalroles_new_update2_aspx", "Functional Role Permissions");
00309             contextNames.Add("ASP.customquery_new_aspx", "Custom query");
00310             contextNames.Add("ASP.customtables2_new_aspx", "Custom table");
00311             contextNames.Add("ASP.customtables3_new_aspx", "Custom table 2");
00312             contextNames.Add("ASP.customtables1_new_aspx", "Table Selection");
00313             contextNames.Add("ASP.accountrequest_aspx", "Account Request");
00314             contextNames.Add("ASP.addeditusers_new_aspx", "Add edit users");
00315             contextNames.Add("ASP.customqueryraiscustomization_aspx", "Assign query");
00316             contextNames.Add("ASP.editdataroles_new_update2_aspx", "Data Role Permissions");
00317             contextNames.Add("ASP.customnodes_new_aspx", "Customise menu nodes");
00318             contextNames.Add("ASP.userstatus_aspx", "User status");
00319             contextNames.Add("ASP.customqueryparameters_aspx", "Custom query parameters");
00320             contextNames.Add("ASP.edithelp_aspx", "Edit help");
00321         }
00322 
00326         private void InitializeTranslations()
00327         {
00328             bool showUntranslatedOnly = this.RBLoptions.SelectedIndex != 0;
00329             if (this.CBshowAllContexts.Checked)
00330             {
00331                 this.SelectedTranslations = RAIS.ApplicationLogicLayer.Localisation.GetAllTranslations(      this.SelectedSourceCulture,
00332                                                                                                              this.SelectedTargetCulture,
00333                                                                                                              showUntranslatedOnly,
00334                                                                                                                                                                                                                          this.SortExpression,
00335                                                                                                                                                                                                                          this.SortDirection);
00336             }
00337             else
00338             {
00339                 this.SelectedTranslations = RAIS.ApplicationLogicLayer.Localisation.GetTranslationsByContext(this.SelectedContext,
00340                                                                                                              this.SelectedSourceCulture,
00341                                                                                                              this.SelectedTargetCulture,
00342                                                                                                              showUntranslatedOnly,
00343                                                                                                                                                                                                                          this.SortExpression,
00344                                                                                                                                                                                                                          this.SortDirection);
00345                         }
00346 
00347             this.gwCaptions.DataSource = this.SelectedTranslations.Values;
00348             this.gwCaptions.RowDataBound+= new GridViewRowEventHandler(gwCaptions_RowDataBound);
00349             this.gwCaptions.DataBind();
00350         }
00351 
00352         private string GetContextNameByLocation(string location)
00353         {
00354             if (!contextNames.ContainsKey(location)) return location;
00355             return contextNames[location];
00356         }
00357 
00358         void gwCaptions_RowDataBound(object sender, GridViewRowEventArgs e)
00359         {
00360             if (e.Row.RowType == DataControlRowType.DataRow)
00361                 ((TextBox)e.Row.Cells[1].Controls[1]).Attributes["onclick"] =
00362                     "SelectContext(" + GetContextIndex(((RAIS.Common.Localization.TranslationItem)e.Row.DataItem).ContextName) + ");";
00363         }
00364 
00365         public int GetContextIndex(string name)
00366         {
00367             ListItemCollection coll = this.DDLcontext.Items;
00368             return coll.IndexOf(coll.FindByValue(name));
00369         }
00370 
00374         private void Autocomplete()
00375         {
00376             TranslationItems translations = this.SelectedTranslations;
00377 
00378             System.Collections.Generic.Dictionary<string, string> initialTranslations = new Dictionary<string,string>();
00379             System.Collections.Generic.Dictionary<string, string> repeatingTranslations = new Dictionary<string,string>();
00380 
00381             //fill up initial translaitons' collection
00382             foreach (GridViewRow row in gwCaptions.Rows)
00383             {
00384                 TextBox txtDestLanguageCaption = (TextBox)row.FindControl(RAIS.UI.Common.Constants.TRANSLATION_EDIT_TEXT);
00385                 HiddenField hdnTranslationName = (HiddenField)row.FindControl(RAIS.UI.Common.Constants.TRANSLATION_ITEM_NAME);
00386 
00387                 string sourceText = translations[hdnTranslationName.Value].SourceText;
00388                 if (!string.IsNullOrEmpty(txtDestLanguageCaption.Text) && !initialTranslations.ContainsKey(sourceText))
00389                 {
00390                     initialTranslations.Add(sourceText, txtDestLanguageCaption.Text);
00391                 }
00392             }
00393             foreach (GridViewRow row in gwCaptions.Rows)
00394             {
00395                 TextBox txtDestLanguageCaption = (TextBox)row.FindControl(RAIS.UI.Common.Constants.TRANSLATION_EDIT_TEXT);
00396                 HiddenField hdnTranslationName = (HiddenField)row.FindControl(RAIS.UI.Common.Constants.TRANSLATION_ITEM_NAME);
00397 
00398                 string sourceText = translations[hdnTranslationName.Value].SourceText;
00399                 if (string.IsNullOrEmpty(txtDestLanguageCaption.Text) && initialTranslations.ContainsKey(sourceText))
00400                 {
00401                     txtDestLanguageCaption.Text = initialTranslations[sourceText];
00402                 }
00403             }
00404 
00405             string actionMessage = RAIS.Common.Messages.AUTOCOMPLETED_TRANSLATIONS;
00406             RAIS.UI.Common.MessageDisplay.DisplayReturnMessage(this.LBLresult, actionMessage, true);
00407         }
00411         private void EnableDisableControls()
00412         {
00413             bool showUntranslatedOnly = this.RBLoptions.SelectedIndex != 0;
00414 
00415             //this.gwCaptions.Enabled      = this.EditMode;
00416                         foreach (GridViewRow row in gwCaptions.Rows)
00417             {
00418                 if(!this.EditMode)
00419                                     ((TextBox)row.FindControl(RAIS.UI.Common.Constants.TRANSLATION_EDIT_TEXT)).Attributes["readOnly"] = "true";
00420             }
00421             this.BTNedit.Enabled         = !this.EditMode;
00422             this.btnSubmit.Enabled       = this.EditMode;
00423             this.BTNdiscard.Enabled      = this.EditMode;
00424             this.BTNautocomplete.Enabled = this.EditMode && this.CBshowAllContexts.Checked && !showUntranslatedOnly;
00425 
00426             this.RBLoptions.Enabled         = !this.EditMode;
00427             this.CBshowAllContexts.Enabled  = !this.EditMode;
00428             this.DDLcontext.Enabled         = !this.EditMode;
00429             this.DDLdestination.Enabled     = !this.EditMode;
00430 
00431             UI.Common.UserManagement.EnableCommonControls(this, !this.EditMode);
00432             this.LBLadmin.ForeColor = RAIS.UI.Common.Constants.COLOR_OF_MENU_BAR_TEXT_HIGHLIGHT;
00433         }
00434         #endregion
00435         #region Private properties
00436 
00439         private TranslationItems SelectedTranslations
00440         {
00441             get
00442             {
00443                 return (TranslationItems)this.ViewState["TranslationItems"];
00444             }
00445             set
00446             {
00447                 this.ViewState["TranslationItems"] = value;
00448             }
00449         }
00453         private RAIS.Common.Localization.Culture SelectedSourceCulture
00454         {
00455             get
00456             {
00457                 Cultures cultures = RAIS.ApplicationLogicLayer.Localisation.SupportedLanguages;
00458                 if (this.DDLsource.Items.Count > 0 && cultures.ContainsKey(this.DDLsource.SelectedItem.Text))
00459                     return cultures[this.DDLsource.SelectedItem.Text];
00460                 else
00461                     return null;
00462             }
00463 
00464             set
00465             {
00466                 ListItem seletedItem = this.DDLsource.Items.FindByText(value.Name);
00467                 if ( seletedItem != null)
00468                    this.DDLsource.SelectedValue = seletedItem.Value;
00469             }
00470         }
00474         private RAIS.Common.Localization.Culture SelectedTargetCulture
00475         {
00476             get
00477             {
00478                 Cultures cultures = RAIS.ApplicationLogicLayer.Localisation.SupportedLanguages;
00479                 if (this.DDLdestination.Items.Count > 0 && cultures.ContainsKey(this.DDLdestination.SelectedItem.Text))
00480                     return cultures[this.DDLdestination.SelectedItem.Text];
00481                 else
00482                     return null;
00483             }
00484 
00485             set
00486             {
00487                 ListItem seletedItem = this.DDLdestination.Items.FindByText(value.Name);
00488                 if (seletedItem != null)
00489                     this.DDLdestination.SelectedValue = seletedItem.Value;
00490             }
00491         }
00495         private RAIS.Common.Localization.Context SelectedContext
00496         {
00497             get
00498             {
00499                 Contexts contexts = RAIS.ApplicationLogicLayer.Localisation.Contexts;
00500                 if (this.DDLcontext.Items.Count > 0 && contexts.ContainsKey(this.DDLcontext.SelectedValue))
00501                     return contexts[this.DDLcontext.SelectedValue];
00502                 else
00503                     return null;
00504             }
00505         }
00509         bool EditMode
00510         {
00511             get
00512             {
00513                 if (this.Session[RAIS.UI.Common.Constants.TRANSLATIONS_EDIT_MODE_TAG] != null)
00514                     return (bool)this.Session[RAIS.UI.Common.Constants.TRANSLATIONS_EDIT_MODE_TAG];
00515                 else
00516                     return false;
00517             }
00518             set
00519             {
00520                 this.Session[RAIS.UI.Common.Constants.TRANSLATIONS_EDIT_MODE_TAG] = value;
00521                                 this.gwCaptions.AllowSorting = !this.EditMode;
00522                                 this.InitializeTranslations();
00523                                 this.EnableDisableControls();
00524                         }
00525         }
00529                 protected UserData CurrentUser
00530                 {
00531                         get { return (UserData)this.Session[UI.Common.Constants.CURRENT_USER_TAG]; }
00532                 }
00536                 protected string SortExpression
00537                 {
00538                         get
00539                         {
00540                                 return (string)(ViewState["sortExpression"]);
00541                         }
00542                         set
00543                         {
00544                                 ViewState.Add("sortExpression", value);
00545                         }
00546                 }
00550                 protected string SortDirection
00551                 {
00552                         get
00553                         {
00554                                 return (string)(ViewState["sortDirection"]);
00555                         }
00556                         set
00557                         {
00558                                 ViewState.Add("sortDirection", value);
00559                         }
00560                 }
00561                 #endregion
00562 
00563         protected void gwCaptions_PageIndexChanging(object sender, GridViewPageEventArgs e)
00564         {
00565             gwCaptions.PageIndex = e.NewPageIndex;
00566             InitializeTranslations();
00567         }
00568 
00569         protected void BTNEditContext_Click(object sender, EventArgs e)
00570         {
00571             if (DDLcontext.Visible)
00572             {
00573                 DDLcontext.Visible = false;
00574                 TBContext.Visible = true;
00575                 BTNEditContext.Text = "OK";
00576                 BTNDeleteContext.Text = "Cancel";
00577             }
00578             else
00579             {
00580                 DDLcontext.Visible = true;
00581                 TBContext.Visible = false;
00582                 BTNEditContext.Text = "Edit";
00583                 BTNDeleteContext.Text = "Delete";
00584                 ApplicationLogicLayer.UserManagement.UpdateContextVisibleName(DDLcontext.SelectedValue, TBContext.Text);
00585                 string selectedValue = DDLcontext.SelectedValue;
00586                 UI.Common.Localisation.InitializeContextsList(this.DDLcontext.Items);
00587                 this.DDLcontext.Items.FindByValue(selectedValue).Selected = true;
00588             }
00589         }
00590 
00591         protected void BTNDeleteContext_Click(object sender, EventArgs e)
00592         {
00593             if (DDLcontext.Visible)
00594             {
00595                 ApplicationLogicLayer.UserManagement.DeleteContext(DDLcontext.SelectedValue);
00596                 UI.Common.Localisation.InitializeContextsList(this.DDLcontext.Items);
00597             }
00598             else
00599             {
00600                 DDLcontext.Visible = true;
00601                 TBContext.Visible = false;
00602                 BTNEditContext.Text = "Edit";
00603                 BTNDeleteContext.Text = "Delete";
00604             }
00605         }
00606     }
00607 }